<!DOCTYPE html>
<html>
<head>
<!-- 验证信息 -->
<link href="${request.getContextPath()}/Public/css/payment.css"
	rel="stylesheet" type="text/css">
<style type="text/css">

.input-inline_text {
    display: inline-block;
    width: 150px;
    vertical-align: middle;
}
.modal-footer {
    padding: 15px;
    text-align: center;
}
</style>
</head>
<!-- 模态窗口编辑模板 -->
<form action="" id="myform" class="form-horizontal form-bordered" novalidate="novalidate" method="post">
<!-- 窗口标题开始 -->
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
	<h4 class="modal-title">新增管理员</h4>
</div>
<!-- 窗口标题结束-->
<!-- 内容开始 -->
<form role="form" class="form-horizontal" id="myFormItems" name="myFormItems">
<div class="modal-body">
	<div class="portlet-body form">
		<div class="form-body">
		  <!-- <div class="form-group">
		    <label for="alarmReason" class="col-sm-2 control-label">报警原因</label>
		    <div class="col-sm-10">
				<textarea class="form-control" rows="5" id="alarmReason" placeholder="请输入报警原因"></textarea>
		    </div>
		  </div>
		  <div class="form-group">
		    <label for="dealremark" class="col-sm-2 control-label">处理结果</label>
		    <div class="col-sm-10">
		    	<textarea class="form-control" rows="5" id="dealremark" placeholder="请输入处理结果"></textarea>
		    </div>
		  </div> -->
		  <div class="form-group">
		    <label for="inputEmail3" class="col-sm-4 control-label">管理员姓名</label>
		    <div class="col-sm-8">
		      <input type="text" class="form-control input-inline_text" id="accountName" name="accountName" placeholder="管理员姓名" onblur="isName(this)">
		    </div>
		  </div>
		  
		  <div class="form-group">
		    <label for="inputPassword3" class="col-sm-4 control-label">登录名</label>
		    <div class="col-sm-8">
	     	 	<input type="text" class="form-control input-inline_text" id="loginName" name="loginName" placeholder="登录名" onblur="checkAccount()"> @smm.cn
		      	<i style="display: none" class="fa fa-times-circle red">&nbsp;</i>
				<div id="wearing" class="col-sm-4 alter-s font13 tips">
					<span class="block triangle"></span><span
						class="block triangle-w"></span>
					<p>
						<i class="fa fa-close red" id="">&nbsp;</i>该邮箱已经注册!
					</p>
				</div>
		    </div>
		  </div>
		  
		  <div class="form-group">
		    <label for="inputPassword3" class="col-sm-4 control-label">操作权限</label>
		    <div class="col-sm-8">
		      <!-- <input type="text" class="form-control input-inline_text" id="inputPassword3"> -->
		      <select  class="form-control input-inline_text" name="roleId" id="roleId">
		      	<#if roleList ??>
		      		<#list roleList as role>
		      			<option value="${role.id}">--${role.roleName!'--'}--</option>
		      		</#list>
		      	</#if>
		      </select>
		    </div>
		  </div>
		  
		</div>
	</div>
</div>
</form>
<!-- 内容结束 -->
<!-- 底部按钮开始 -->
<div class="modal-footer">
	<button type="button" class="btn red  fa fa-check" onclick="submitForm();"> 确认</button>
	<button type="button" class="btn default fa fa-times" data-dismiss="modal"> 取消</button>
</div>
<!-- 结束 -->
</form>
<!-- 新增管理员-->
<script>
//注册用户时，判断邮箱是否已经被注册过!
var checkLoginName = "true";
function checkAccount(){
	$.ajax({
		type: "POST",
		url: "${request.getContextPath()}/sysManager/checkLoginName.do",
		data:{"loginName":$("#loginName").val()},
		dataType: "json",
		success: function(res){
			if(res.code=="success"){
				$(".tips").show("slow");
				checkLoginName = "false";
			}else{
				$(".tips").hide("slow");
				checkLoginName = "true";
			}
		}
});
}

function submitForm(){
	if($("#accountName").val()==null || $("#accountName").val()==""){
		layer.alert('请输入管理员姓名!', {
		    icon: 0,
		    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
		})
		/* layer.alert('请输入管理员姓名!', 0, '提示', function(index) {
			layer.close(index);
		}); */
		return false;
	}
	if($("#loginName").val() == null || $("#loginName").val()==""){
		layer.alert('请输入登录名!', {
		    icon: 0,
		    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
		})
		/* layer.alert('请输入登录名!', 0, '提示', function(index) {
			layer.close(index);
		}); */
		return false;
	}
	if(checkLoginName == "false"){
		return false;
	}
	//后台提交
	var accessAddress = getRootPath();
	$.ajax({
    		type: "POST",
    		url: "${request.getContextPath()}/sysManager/addAccount.do",
    		data:{"accountName":$("#accountName").val(),"loginName":$("#loginName").val(),"roleId":$("#roleId").val(),"accessAddress":accessAddress},
    		dataType: "json",
    		success: function(res){
    			if(res.code=="succ"){ 
    				$(".editModal").modal('hide');
    				$(".editModal").empty();
   					CommonUtils.succModal2('系统提示','新增成功',"${request.getContextPath()}/sysManager/accountList.do");
    			}
    			else{
    				CommonUtils.succModal('系统提示','新增失败',"${request.getContextPath()}/sysManager/accountList.do");
    			}
    		}
   });
}

function isName(Object){
	//alert(Object.value);
}

//获取访问地址 
function getRootPath() {

	var curWwwPath = window.document.location.href;
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	var localhostPaht = curWwwPath.substring(0, pos);
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	return (localhostPaht + projectName);
}
</script>
</html>